#ifndef MODBUS_RTU_SLAVE_H
#define MODBUS_RTU_SLAVE_H

#include <QMainWindow>
#include <QModbusRtuSerialSlave>
#include <QStandardItemModel>

namespace Ui {
class modbus_rtu_slave;
}

class modbus_rtu_slave : public QMainWindow
{
    Q_OBJECT

public:
    modbus_rtu_slave(QWidget *parent = nullptr);
    ~modbus_rtu_slave();

private slots:
    void on_connectButton_clicked();
    void updateRegisterValue(const QModelIndex &topLeft, const QModelIndex &bottomRight);
    void handleDeviceError(QModbusDevice::Error error);

private:
    Ui::modbus_rtu_slave *ui;
    QModbusRtuSerialSlave *modbusDevice = nullptr;
    QStandardItemModel *registersModel = nullptr;
    void setupModbusSlave();
    void setupRegistersTable();
    void updateUiState(bool connected);
};

#endif // MODBUS_RTU_SLAVE_H
